<template lang="pug">
  kalix-dialog.user-add(bizKey="departments" ref="kalixBizDialog"
  v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" v-bind:submitBefore="getCodeByPid")
    div.el-form(slot="dialogFormSlot")
      input(v-model="formModel.parentId" type="hidden")
      input(v-model="formModel.isLeaf" type="hidden")
      el-form-item(label="添加院系名称" prop="content" label-width="120px" v-bind:rules="rules.content")
        el-input(v-model="formModel.content" style="width:80%")
</template>

<script type="text/ecmascript-6">
  import {DepartmentsURL} from '../../config.toml'
  import FormModel from './model'

  export default {
    name: 'DepartmentsAdd',
    data() {
      return {
        formModel: Object.assign({}, FormModel),
        labelWidth: '170px',
        rules: {
          content: [{required: true, message: '请输入内容', trigger: 'blur'}]
        },
        targetURL: DepartmentsURL
      }
    },
    methods: {
      getCodeByPid(baseDialog, callBack) { // 获取诊断代码（code）并赋值
        this.axios.request({
          method: 'GET',
          url: DepartmentsURL + '/getCodeByPid',
          params: {
            parentId: this.formModel.parentId
          }
        }).then(res => {
          console.log('res.data.data.data=================', res.data)
          baseDialog.formModel.code = res.data
          callBack()
        })
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 70%
    margin auto
    .el-input
      width 70%
    .radio
      margin-left 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px

</style>
